<?php
/**
 * 菜系管理
 * @author shitou
 *
 */
class CuisineAction extends CommonAction{
	
	/**
	 * 菜系管理
	 */
	public function index(){
		
		$view = sendRest("BDC/Outlet/dictAddress");
		$this->assign("dictAddressCN",$view['data']['zh-cn']['array']);
		$this->assign("dictAddressEN",$view['data']['en-us']['array']);
		
		if(IS_AJAX){
			$desc    = $this->_param("orderDirection","trim","desc");;
			$order   = $this->_param("orderName","trim","addtime");
			$pageNum = $this->_param("pageNum","intval",C('PAGE_NUMS'));
			$nowPage = $this->_param("nowPage","intval",1);
			$where   = $this->_param("where","trim","");
			
			$map   = array("where"=>$where,"pageNum"=>$pageNum, "nowPage"=>$nowPage, "orderDirection"=>$desc ,"orderName"=>$order);
			if(C('ADMIN_ROLE')==session(C('USER_AUTH_ROLE'))){
				$map['noCheckRole'] = 1;
			}
			
			$json  = sendRest("BDC/Cuisine/index",$map);
			$data  = $json['data'];
			$count = $data['count'];
	
			$totalPage = ceil($count/$pageNum);
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'totalPage'=>$totalPage);
			
			foreach($data['list'] AS $row){
				
				$city = $view['data']['zh-cn']['array'][$row['city']][0];
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'           => $row['id'],
						'city'         => $city,
						'title'        => $row['title'],
						'entitle'      => $row['entitle'],
						'addtime'      => date('Y-m-d H:i:s',$row['addtime']),
					),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,"JSON");
		}else{
			$this->display();
		}
	}
	
	
	/**
	 * 添加菜系
	 */
	public function add(){
		
		if(IS_AJAX){
			$data   = sendRest("BDC/Cuisine/add",$_POST,'post');
    		$this->ajaxReturn($data);
				
		}else{
	
			$data = sendRest("BDC/Outlet/dictAddress");
			$this->assign("dictAddressCN",$data['data']['zh-cn']['array']);
			$this->assign("dictAddressEN",$data['data']['en-us']['array']);
			$this->display();
		}
	}
	
	
	/**
	 * 修改菜系
	 */
	public function edit(){
		 
		if(IS_AJAX){
			
			$json = sendRest("BDC/Cuisine/edit",$_POST);
			$this->ajaxReturn($json);
			 
		}else{
			
			$data = sendRest("BDC/Outlet/dictAddress");
			$this->assign("dictAddressCN",$data['data']['zh-cn']['array']);
			$this->assign("dictAddressEN",$data['data']['en-us']['array']);
			
			$map['id']  = $this->_get("id","intval",0);
			$json       = sendRest("BDC/Cuisine/detail",$map);
			
			//查询城市数据字典的级别
			if($json['data']['area']){
				$dict = D("Dict");
				$row  = $dict->find($data['data']['area']);
				$this->assign("row",$row);
			}
			
			$this->assign("detail", $json['data']);
			$this->display();
		}
	}
	
	
	/**
	 * 删除菜系
	 */
	public function del(){
		 
		if(IS_AJAX){
	
			$map['val'] = $this->_param("id","intval",0);
			$json = sendRest("BDC/Cuisine/del",$map);
	
			$this->ajaxReturn($json);
		}
	}
}

?>